package com.atguigu.lease.web.admin.controller.apartment;


import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.PaymentType;
import com.atguigu.lease.web.admin.service.impl.PaymentTypeServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Tag(name = "支付方式管理")
@RequestMapping("/admin/payment")
@RestController
public class PaymentTypeController {

    @Autowired
    private PaymentTypeServiceImpl paymentTypeService;

    /**
     * 知识点 ：1. mybatis 逻辑删除注解
     *         2. jsonIgnore 注解 字符串序列化时 忽略 该注解修饰 变量
     * @return
     */
    @Operation(summary = "查询全部支付方式列表")
    @GetMapping("list")
    public Result<List<PaymentType>> listPaymentType() {
        return Result.ok(paymentTypeService.list());
    }

    /**
     * is_deleted 自动填充
     * created_timed update_time mybatisPlus 自动填充 第一步 ： 添加注解 （fill -- ），
     *               第二步，创建配置类 MybatisMetaObjectHandler ，进行配置填充内容和时机
     * @param paymentType
     * @return
     */
    @Operation(summary = "保存或更新支付方式")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdatePaymentType(@RequestBody PaymentType paymentType) {
        paymentTypeService.saveOrUpdate(paymentType);
        return Result.ok();
    }

    /**
     * 逻辑删除
     * @param id
     * @return
     */
    @Operation(summary = "根据ID删除支付方式")
    @DeleteMapping("deleteById")
    public Result deletePaymentById(@RequestParam Long id) {
        paymentTypeService.removeById(id);
        return Result.ok();
    }

}















